package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.OrderBill;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IOrderBillService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("orderBill")
public class OrderBillController {

    @Autowired
    private IOrderBillService service;

    @RequestMapping("")
    public String index() {
        return "orderBill/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(QueryObject qo) {
        return service.query(qo);
    }



    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(OrderBill orderBill) {
        JsonResult jsonResult = new JsonResult();
        try {
            service.save(orderBill);
            jsonResult.markMsg("保存成功");
        }catch (Exception e){
            e.printStackTrace();
            jsonResult.markMsg("保存失败");
        }
        return jsonResult;
    }
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(OrderBill orderBill){
        JsonResult result = new JsonResult();
        try {
            service.update(orderBill);
            result.markMsg("编辑成功");
        }catch (Exception e){
            e.printStackTrace();
            result.markMsg("编辑失败");
        }
        return result;
    }

    @RequestMapping("changeAudit")
    @ResponseBody
    public JsonResult changeAudit(Long id){
        JsonResult result = new JsonResult();
        try {
            service.changeAudit(id);
        }catch (Exception e){
            e.printStackTrace();
            result.markMsg("审核失败");
        }
        return result;
    }
}
